<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影详情</title>
    <%- include common %>
</head>

<body>
    <%- include('head',{title:'detail',username:username,mid})%>
        <div class="container" style="margin-top: 60px;margin-bottom: 60px;z-index: 999;">
            <%   result.forEach((item,i)=>{    %>
                <div class="container-fluid">
                    <div class="row">
                        <div class="middle col-md-6 text-center">
                            <h2 class="text-success text-center">
                                <%-item.title %>
                            </h2>
                            <div>
                                <img height="260px" src="<%- item.images.large.replace(/img7/, 'img3') %>" alt="">

                                <div class="text-center">
                                    <!-- <h5 style="margin-top: 10px;">导演:
                                        <%- item.directors.name%>
                                    </h5> -->
                                    <h5 style="margin-top: 10px;">评分：
                                        <%- item.rating.average%>
                                    </h5>
                                    <h5 style="margin-top: 10px;">类型：
                                        <%- item.genres%>
                                    </h5>
                                    <h5 style="margin-top: 10px;">上映时间：
                                        <%- item.year%>
                                    </h5>
                                </div>

                            </div>
                        </div>
                        <div class="end  conment col-md-6" id="<%- item.id%>">
                            <h2 class="text-primary text-center"> 电影评论</h2>
                            <!-- <form action="/conment" method="POST"> -->
                            <textarea class="   form-control" id="conmment_text" rows="4"></textarea>
                            <button type="button" class="btn btn-primary" style="margin-top: 20px;" onclick="conment()">评论</button>
                            <button type="reset" class="btn btn-warning" style="margin-top: 20px;">重置</button>
                            <!-- </form> -->

                        </div>
                    </div>
                </div>
                <%     })%>


        </div>

        <%- include foot%>
</body>

<script>
    var id = $(".conment").attr("id")

    function conment() {
        var id = $(".conment").attr("id")
        $.ajax({
            url: '/conment',
            type: "POST",
            data: {
                text: $("#conmment_text").val(),
                id: id
            },
            success: res => {
                console.log(res)
                if (res.type) {
                    alert(res.msg)
                    location.href = "/allcom"
                }
            }
        })
    }

    $(document).on("ready", function() {
        $.ajax({
            url: '/checkcon',
            type: "POST",
            data: {
                id: id
            },
            success: res => {
                var list = res.result
                var html = ""
                list.forEach((item) => {
                    var time = item.time
                    time = time.split("-")
                    var year = time[0]
                    var month = time[1]
                    var time2 = time[2].split("T")
                    var day = time2[0]
                    var time3 = time[2].split(":")
                    var time4 = time3[0].split("T")
                    var hours = time4[1] * 1 + 8
                    var min = time3[1]
                    html += `
                    <div id="text" class="container-fluid">
                    <p>评论人：${item.username}:</p>
                    <div>评论内容：${item.text}</div>
                    <h5>评论时间：${year}-${month}-${day} ${hours}:${min}</h5>
                    </div>
                    `
                    console.log(time3, time4, time)
                })
                $(".end").append(html)
            }
        })

    })
</script>


<style>
    #text {
        border: 1px solid #000;
        margin-top: 10px;
        margin-bottom: 60px;
    }
</style>


<script>
    $(pageInit);

    function pageInit() {
        $.extend(XHEDITOR.settings, {
            shortcuts: {
                "ctrl+enter": submitForm
            }
        });
        // $("#ele").xheditor();
        $("#conmment_text").xheditor({ //初始化 富文件编辑框
            html5Upload: false,
            upMultiple: "1",

            upLinkRrl: "upload.html",
            upLinkExt: "zip,rar,txt",

            upImgUrl: "/uploadImg", // 图片上传的服务器  
            upImgExt: "jpg,jpeg,gif,png",

            upFlashUrl: "upload.php",
            upFlashExt: "swf",

            upMediaUrl: "upload.php",
            upMediaExt: "wmv,avi,wma,mp3,mid"

        });
    };

    function insertUpload(arrMsg) {
        console.log(arrMsg);
        var i, msg;
        for (var i = 0; i < arrMsg.length; i++) {
            msg = arrMsg[i];
            console.log(msg);
            $("#uploadList").append('<option value="' + msg.id + '">' + msg.localname + '</option>')
        }
    };

    function submitForm() {
        $("#frmDemo").submit();
    }
</script>
</script>

</html>